﻿/**
 * Licensed under the MIT License
 *
 * Copyright (c) 2010 Laurent Berthelot
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */
package marcel.display.draw.shapes
{
	import flash.display.Graphics;
	import flash.geom.Rectangle;
	import marcel.display.draw.props.FillProps;
	import marcel.display.draw.props.LineProps;
	
	
	/**
	 * The BasicShape class contains a set of static methods used for initialize fill and line properties used for draw a vector shape and clean them.
	 * The BasicShape class must be extend.
	 * @author	Laurent Berthelot
	 */
	public class BasicShape extends Object
	{
		
		//--------------------------------------------------------------------------
		//
		//  Constructor
		//
		//--------------------------------------------------------------------------
		/**
		 * Non-instanciable class, only statics methods in BasicShape class.
		 */
		public function BasicShape() {}
		
		//--------------------------------------------------------------------------
		//
		//  Protected static methods
		//
		//--------------------------------------------------------------------------
		/**
		 * @private
		 * Specifies a fill used by subsequent calls to other Graphics methods (such as lineTo() or drawCircle()) for the object.
		 */
		static protected function _beginFill(graphics:Graphics, fp:FillProps = null, rec:Rectangle = null):void {
			if (!fp) return;
			if (fp.gradient) {
				graphics.beginGradientFill(fp.fillType, fp.gradientColor, fp.gradientAlpha, fp.gradientDistrib, fp.getGradientMatrix(rec, fp.rotation));
				return;
			}
			graphics.beginFill(fp.color, fp.alpha);
		}
		
		/**
		 * @private
		 * Specifies a line style used for subsequent calls to Graphics methods such as the lineTo() method or the drawCircle() method.
		 */
		static protected function _lineStyle(graphics:Graphics, lp:LineProps):void {
			if (!lp) return;
			graphics.lineStyle(lp.thickness, lp.color, lp.alpha, lp.pixelHinting, lp.scaleMode, lp.caps, lp.joints, lp.miterLimit);
		}
		
		/**
		 * @private
		 * Applies a fill to the lines and curves that were added since the last call to the _beginFill() method.
		 */
		static protected function _endFill(graphics:Graphics):void {
			graphics.endFill();
		}
		
	}
}